package com.kuangstudy.controller.string;

import com.kuangstudy.entity.User;
import com.kuangstudy.service.UserService;
import com.kuangstudy.vo.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2021/5/20 12:35
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("保存用户信息")
    @PostMapping("/save")
    public R saveUser() {
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setNickname("学相伴用户_" + i);
            user.setPassword("123456" + i);
            user.setSex(i % 2);
            userService.saveupdateUser(user);
        }
        return R.ok();
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/update")
    public R update(@RequestBody User user) {
        userService.saveupdateUser(user);
        return R.ok();
    }


    @ApiOperation("根据用户ID查询用户信息")
    @PostMapping("/getuser/{id}")
    public R getUser(@PathVariable("id") Integer id) {
        User user = userService.getUser(id);
        return R.ok().data("user", user);
    }

}
